package com.sgb.capital.viewmodel;

import com.sgb.capital.api.CapitalManager;
import com.sgb.capital.base.BaseActivity;
import com.sgb.capital.model.BaseEntity;
import com.sgb.capital.model.ReimburseBean;
import com.sgb.capital.utils.DialogHelper;
import com.sgb.capital.view.widget.MToast;

import java.util.HashMap;
import java.util.List;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 作者:张磊
 * 日期:2021/12/15 0015
 * 说明:
 */
public class ReimburseModel extends ViewModel {

    public MutableLiveData<List<ReimburseBean.ListDTO>> mDatas = new MutableLiveData<>();


    /**
     * 待付订单金额和数量统计
     *
     * @param activity
     */
    public void refundPageList(BaseActivity activity, HashMap map) {
        DialogHelper.showProgressDialog(activity, null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        CapitalManager.getInstance().getCapitalAPI().refundPageList(map).enqueue(new Callback<BaseEntity<ReimburseBean>>() {
            @Override
            public void onResponse(Call<BaseEntity<ReimburseBean>> call, Response<BaseEntity<ReimburseBean>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getState().equals(CapitalManager.RESPONSE_OK)) {
                    mDatas.setValue(response.body().getData().list);
                } else {
                    MToast.showToast(activity, response.body().getMsg());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<ReimburseBean>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
                MToast.showToast(activity, t.getMessage());
            }
        });
    }
} 